////-----------------------------------------------------------------------------------------------
//// Author: Andre Van Der Merwe <dart@pobox.com>
//// Project: .net Compound File (http://dotnetpcf.sourceforge.net)
////
//// Modifications
////    2001-02-27: (AVDM) Started using NUnit (http://nunit.sourceforge.net)
//// 
//// Copyright (c) Andre Van Der Merwe 2000-2001
//// Licence: BSD - see the licence.txt file or visit the project homepage
////-----------------------------------------------------------------------------------------------

////TODO the tests in test.cs are VERY messy and undocumented. They need to be fixed and made to work with a unit test util


//namespace dotnetpcf.CompoundFile
//{
//   using System;
//   using System.Diagnostics;
//   using System.Collections;
//   using System.Data;
//   using System.IO;
//   using System.Runtime.InteropServices;
//   using NUnit.Framework;

//   public class Test
//   {
//      /// <summary>
//      /// Used when the project is compiled as a Win32 console app
//      /// </summary>
//      public static void Main()
//      {
//         Test_Performance();
//      }


//      //-----------------------------------------------------------------------
//      // Test collections
//      //------------------
//      public class SysTestTestOnly : NUnit.Framework.TestCase
//      {  
//         public SysTestTestOnly(  string s  ) : base( s ) {}

//         public static NUnit.Framework.ITest Suite
//         {
//            get{ return new NUnit.Framework.TestSuite(  typeof(SysTestTest)  ); }
//         }
//      }


//      public class AllTests : NUnit.Framework.TestCase
//      {  
//         public AllTests(  string s  ) : base( s ) {}

//         public static NUnit.Framework.ITest Suite
//         {
//            get
//            { 
//               NUnit.Framework.TestSuite suite = new NUnit.Framework.TestSuite();
//               suite.AddTest(   new TestSuite(  typeof(SysTestTest)  )   );
//               return suite;
//            }
//         }
//      }
//      //-----------------------------------------------------------------------




//      /// <summary>
//      /// NUnit tests that test the integrity of compound file as a whole.
//      /// </summary>
//      public class SysTestTest : NUnit.Framework.TestCase
//      {
//            //TODO m_sFileName - get path from DLL at runtime (like GetModuleFileName())
//         private string m_sFileName = @"C:\programming\c#\_tools\CompoundFileViewer\test.rtf";

//         public SysTestTest(  string s  ) : base( s ) {}

//         protected override void SetUp()
//         {
//            File f = new File(  m_sFileName  );
//            f.Delete();
//         }

//         protected override void TearDown()
//         {
//            GC.Collect(); //File must be freed
//            File f = new File(  m_sFileName  );
//            f.Delete();
//         }

//         public void Test_CreateSaveLoad()
//         {
//            CompoundFileSys cf = new CompoundFileSys();
//            cf.OpenFile(  m_sFileName  );
//            cf.Save();
//            cf.CloseFile();

//            cf = new CompoundFileSys();
//            cf.OpenFile(  m_sFileName  );
//         }

//         /// <summary>
//         /// Checks that a file and dir are deleted correctly
//         /// </summary>
//         public void Test_DeleteDir()
//         {
//            CompoundFile cf = new CompoundFile();
//            cf.OpenFile(  m_sFileName  );
//            CFDirectory dir = cf.WorkingDirectory.CreateDirectory(  "new"  );
//            CFFile file = dir.CreateFile(  "1"  );
//            dir.DeleteFile(  file.ID  );
//            cf.WorkingDirectory.DeleteDirectory(  dir.ID  );

//            cf.Save();
//            cf.CloseFile();

//            //TODO load & confirm items are deleted also check that blocks are unused
//         }


//         public void Test_PublicInterface()
//         {
//            /////////////////////////////////////////
//            // Create file using internal interface
//            /////////////////////////////////////////
//            {
//               CompoundFile cf = new CompoundFile();
//               cf.OpenFile(  m_sFileName  );
//               //DirTable.DirTableEntry dent;// = cf.m_DirTable.CreateDirectory(  null,  null  );
//               DirTable.DirTableEntry dent1 = cf.DirTable.CreateDirectory(  "1",  null  );
//               DirTable.DirTableEntry dent2 = cf.DirTable.CreateDirectory(  "3",  dent1  );
//               DirTable.DirTableEntry dent3 = cf.DirTable.CreateDirectory(  "4",  dent1  );
//               DirTable.DirTableEntry dent4 = cf.DirTable.CreateDirectory(  "5",  dent2  );
//               DirTable.DirTableEntry dent5 = cf.DirTable.CreateDirectory(  "2",  dent3  );
//               DirTable.DirTableEntry dent6 = cf.DirTable.CreateDirectory(  "6",  dent5  );

//               CFDirectory dir3 = new CFDirectory(  cf,  dent1  );
//               dir3.CreateFile(  "file 1"  );

//               Stream strm = dir3.Files[ 0 ].OpenFile();
//               StreamWriter wrtr = new StreamWriter(  strm  );
//               wrtr.Write(  "file 1 file 1 file 1"  );
//               wrtr.Close();


//               CFDirectory dir6 = new CFDirectory(  cf,  dent5  );
//               dir6.CreateFile(  "file 2"  );

//               strm = dir6.Files[ 0 ].OpenFile();
//               //for(  int i = 0;  i < SysInfo.BLOCK_BYTE_SIZE + 100;  ++i  )
//               //   strm.WriteByte(  (byte)i  );
//               strm.Close();
               

//               CFDirectory dirA = new CFDirectory(  cf,  dent2  );
//               dirA.CreateFile(  "a file"  );

//               strm = dirA.Files[ 0 ].OpenFile();
//               BinaryWriter wrtr2 = new BinaryWriter(  strm  );
//               wrtr2.Write(  "data for a file"  );
//               //wrtr2.Write(  (uint)12  );
//               //wrtr2.Write(  (long)0  );
//               //wrtr2.Write(  (byte)0xf0  );
//               wrtr2.Write(  "more data"  );
//               wrtr2.Close();


//               DirTable.DirTableEntry dent0 = cf.DirTable.GetDirTableEntryByID(  cf.WorkingDirectory.ID  );
//               CFDirectory dir0 = new CFDirectory(  cf,  dent0  );
//               dir0.CreateFile(  "file 0"  );

//               strm = dir0.Files[ 0 ].OpenFile();
//               wrtr = new StreamWriter(  strm  );
//               wrtr.Write(  "I'm writing to file 0 in dir 0 here"  );
//               wrtr.Close();

               
//               cf.Save();
//               cf.CloseFile();
//            }

//            ///////////////////////////////
//            // Open using public interface
//            ///////////////////////////////
//            {
//               CompoundFile cf = new CompoundFile();
//               cf.OpenFile(  m_sFileName  );

//               //cf.MoveToRootDirectory();
//               //cf.WorkingDirectory.DeleteFile(  "file 0"  );

//               //cf.Save();
//               cf.CloseFile();
//            }
//         }

        
//         public void Test_Dir()
//         {
//            CompoundFileSys cf = new CompoundFileSys();
//            cf.OpenFile(  m_sFileName  );
//            DirTable.DirTableEntry dent = cf.DirTable.CreateDirectory(  null,  null  );
//            dent = cf.DirTable.CreateDirectory(  null,  null  );
//            DirTable.DirTableEntry dent1 = cf.DirTable.CreateDirectory(  "Another dir",  null  );
//            dent = cf.DirTable.CreateDirectory(  "Another dir",  dent1  );
//            dent = cf.DirTable.CreateDirectory(  "and more and more and more and more...",  dent1  );
//            dent = cf.DirTable.CreateDirectory(  "This is a dir name",  dent  );
//            //Debug.Assert(  null != dent  );
//            cf.Save();
//            cf.CloseFile();

//            cf = new CompoundFileSys();
//            cf.OpenFile(  m_sFileName  );

//            IDictionaryEnumerator elems = cf.DirTable.GetEntryEnumerator();
//            Debug.Write(   "\r\n"  );
//            while(  elems.MoveNext()  )
//               Debug.Write(   "dir entry: " + ((DirTable.DirTableEntry)elems.Value).Name + "\r\n"   );
//         }

//         /// <summary>
//         /// Write 50 blocks to a new file.
//         /// Load file, load data and compare
//         /// </summary>
//         public void Test_ReadWrite() 
//         {
//            byte[] arWrite = new byte[ SysInfo.BLOCK_BYTE_SIZE * 50 ];
//            for(  int i = 0;  i < arWrite.Length;  ++i  )
//               arWrite[ i ] = (byte)i;

//            {
//               CompoundFile cf = new CompoundFile();
//               cf.OpenFile(  m_sFileName  );
//               CFFile file = cf.WorkingDirectory.CreateFile(  "test"  );

//               FSFilterStream strm = file.OpenFile();
//               strm.Write(  arWrite,  0,  arWrite.Length  );
//               strm.Close();

//               file = cf.WorkingDirectory.CreateFile(  "2"  );
//               strm = file.OpenFile();
//               strm.WriteByte(  1  );
//               strm.Close();

//               cf.Save();
//               cf.CloseFile();
//            }

//            {
//               CompoundFile cf = new CompoundFile();
//               cf.OpenFile(  m_sFileName  );

//               CFFile file = null;

//               foreach(  CFFile find in cf.WorkingDirectory.Files  )
//               {
//                  if(  "test" == find.Name  )
//                  {
//                     file = find;
//                     break;
//                  }
//               }

//               FSFilterStream strm = file.OpenFile();

//               byte[] arRead = new byte[ arWrite.Length ];
               
//               strm.Read(  arRead,  0,  arWrite.Length  );

//               for(  int i = 0;  i < arWrite.Length;  ++i  )
//                  Debug.Assert(  arWrite[ i ] == arRead[ i ],  "mismatch " + i.ToString()  );
            
//            }
//         }
//      }


     
//      /// <summary>
//      /// Write several mb of data to a new file and then read it.
//      /// Used to measure read/write performance
//      /// </summary>
//      public static void Test_Performance() 
//      {
//         File f = new File(  @"C:\programming\c#\_tools\CompoundFileViewer\test.rtf"  );
//         f.Delete();

//         CompoundFile cf = new CompoundFile();
//         cf.OpenFile(  @"C:\programming\c#\_tools\CompoundFileViewer\test.rtf"  );

//         {
//            CFFile file = cf.WorkingDirectory.CreateFile(  "new"  );
//            Stream strmW = file.OpenFile();
            
//            byte[] ar = new byte[ 8637952 ];
//            strmW.Write(  ar,  0,  ar.Length  );
//            strmW.Close();
//         }
//         cf.Save();

//         Stream strm = cf.WorkingDirectory.Files[ 0 ].OpenFile();
//         StreamReader rdr = new StreamReader(  strm  );

//         string s = rdr.ReadToEnd();
//         rdr.Close();
//         cf.CloseFile();
//      }
//   }
//}
